#ifndef XIMCP_H
#define XIMCP_H
#include "xnet_tiny.h"
#include "xnet_err.h"
#include "xip.h"
#include "gdbinfo.h"
#include "protocol.h"

// 是icmp_hdr的type
#define XICMP_CODE_ECHO_REQUEST 8 // 回显请求
#define XICMP_CODE_ECHO_REPLY 0   // 回显响应

// icmp 包头
#pragma(0)
typedef struct _xicmp_hdr_t
{
    uint8_t type; // 是ping的请求还是响应
    uint8_t code; // 对type进一步分类，在ping里都是0
    uint16_t checksum;
    uint16_t id;
    uint16_t seq;
} xicmp_hdr_t;
#pragma()

typedef enum _xicmp_unreach_type
{
    XICMP_TYPE_UNREACH = 3,
    XICMP_CODE_PORT_UNREACH = 3,
    XICMP_CODE_PRO_UNREACH = 2
} xicmp_unreach_type;

void xicmp_init(void);

void xicmp_in(xipaddr_t *src_ip, xnet_packet_t *packet);
xnet_err_t reply_icmp_request(xicmp_hdr_t *icmp_hdr, xipaddr_t *src_ip, xnet_packet_t *origin_packet);
xnet_err_t xicmp_dest_unreach(xicmp_unreach_type code, xip_hdr_t *ip_hdr);

#endif // XIMCP_H